
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="distributorSalesSearch.do"/>
<%@ page import="com.scalar.chiptrack.utils.ConfigManager,java.util.Calendar,java.util.ArrayList,
                        com.scalar.chiptrack.utils.StringUtils"%>
<%String chipTracContext = "/" + ConfigManager.getChipTracContext(); /*try{*/%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>

<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>

<SCRIPT language="JavaScript">

    var dateElement = "";
    function openCalendar(dateValue)
    {
        dateElement = dateValue;
        newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
        newWindow.moveTo(550,180);
        newWindow.focus();
    }

    function assignDate(passedValue)
    {
        dateElement.value=passedValue;
        window.focus();
    }

    function validateFromAndToDates()
    {
        var formdoc = document.distributorSearchForm;
        errMsg = '';

        var pa	= document.getElementById("errors")

        if(chkDate(formdoc.fromDate.value,'From-Date','N') == false)
        {
            pa.innerHTML = errMsg;
            formdoc.fromDate.focus();
            return false;
        }

        if(chkDate(formdoc.toDate.value,'To-Date','N') == false)
        {
            pa.innerHTML = errMsg;
            formdoc.toDate.focus();
            return false;
        }

        if(formdoc.fromDate.value!='' && formdoc.toDate.value!='')
        {
            if (!validateDateOut(formatDateAsMMDDYYYY(formdoc.fromDate.value),formatDateAsMMDDYYYY(formdoc.toDate.value)))
            {
                pa.innerHTML = "To Date cannot be less than From Date";
                formdoc.toDate.focus();
                return false;
            }
        }
        return true;
    }

    function submitPage(fileType)
    {
        var form = document.distributorSearchForm;
        var d = new Date();
		var day = d.getDate();
		var month = d.getMonth()+1;
		var year = d.getFullYear();
		var hour = d.getHours();
		var min = d.getMinutes();
		var sec = d.getSeconds();

		var defaultPrompt = day+"/"+month+"/"+year+":"+hour+":"+min+":"+sec;

		//var reporttype        = "";

        var success;
        success = true;
        success = validateFromAndToDates();

        if( form.fromDate.value != '' && success == true  )
        {
            var array = (form.fromDate.value).split("/");
            if ( array[0] < 10 && array[0].length < 2)
                array[0] = "0"+array[0];
            if ( array[1] < 10 && array[1].length < 2 )
                array[1] = "0"+array[1];
            form.fromDate.value = array[0]+"/"+array[1]+"/"+array[2];
        }
        if( form.toDate.value != '' && success == true  )
        {
            var array = (form.toDate.value).split("/");
            if ( array[0] < 10 && array[0].length < 2)
                array[0] = "0"+array[0];
            if ( array[1] < 10 && array[1].length < 2 )
                array[1] = "0"+array[1];
            form.toDate.value = array[0]+"/"+array[1]+"/"+array[2];
        }
        if( success == false )
        {
           return false;
        }
        var reportType = "";

        for ( var i = 0; i < form.reportType.length; i++ )
        {
            if ( form.reportType[i].checked )
            {
                reportType = form.reportType[i].value;
            }
        }

		if ( form.distributorId.value == '')
        {
            form.prompt0.value='0';
        }
		else
        {
            form.prompt0.value = form.distributorId.options[form.distributorId.selectedIndex].value;
        }

        if ( form.fromDate.value == '')
        {
            form.prompt1.value='0';
        }
		else
        {
            form.prompt1.value = form.fromDate.value;
        }

        if ( form.toDate.value == '')
        {
            form.prompt2.value='0';
        }
		else
        {
            form.prompt2.value = form.toDate.value;
        }

		form.prompt3.value = defaultPrompt;

		form.prompt4.value ='Crystal';
		form.prompt5.value ='salesReport';
		form.prompt6.value ='';
		form.prompt7.value='';
		form.prompt8.value ='';
		form.prompt9.value ='';
		form.prompt10.value ='';
		form.prompt11.value ='';

        if ( fileType == 1 )
        {
		    form.action="<%=chipTracContext%>/jsp/report.jsp?nameReport=Operations/distributor_sales_report.rpt";
        }
        else
        {               
            form.action="<%=chipTracContext%>/distributorSalesSearch.do?action=excelReport";;
        }

        form.submit();
        return true;
    }

</SCRIPT>

<!-- Top Header Start-->

<%@ include file="/jsp/includes/header.jsp" %>

<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border="0">
	<TBODY>
	<TR>
		<td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
        <!-- Side Navigation start -->
		<%@ include file="/jsp/operations/reports_side_menu.jsp" %>
        <!-- end of the side navigations -->
		</td>
		<td bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=10></td>
		<td valign="top" width="100%">
			<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0><BR>
            <!-- from here your body starts -->
			<html:form name="distributorSearchForm" method="post" action="/distributorSalesSearch" type="com.scalar.chiptrack.operations.distributor.forms.DistributorSearchForm">
                <table border="0" width="100%" align=right>
                <TR><TD colspan="6" class="NArialW" align="center">Distributor Report</TD></TR>
                <tr><td colspan="6" class="NArialL" align="left"><font color="FF0000"><FONT id="errors"></FONT></font></td></tr>
                <tr><td colspan="6" id="svrErrors"><chiptrack:errors styleClass="NArialL"/></td></tr>
                <tr><td colspan="6" id="svrInfo"><chiptrack:info styleClass="NArialL"/></td></tr>
                <tr><td colspan="6"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>

                <tr>
                    <td width="15%">
                        <input type="hidden" name="prompt0">
                        <input type="hidden" name="prompt1">
                        <input type="hidden" name="prompt2">
                        <input type="hidden" name="prompt3">
                        <input type="hidden" name="prompt4">
                        <input type="hidden" name="prompt5">
                        <input type="hidden" name="prompt6">
                        <input type="hidden" name="prompt7">
                        <input type="hidden" name="prompt8">
                        <input type="hidden" name="prompt9">
                        <input type="hidden" name="prompt10">
                        <input type="hidden" name="prompt11">
                    </td>
                    <td width="15%"><font class="NArialL">Distributor Name : </font></td>
                    <td width="15%"><font class="NArialL">
                        <html:select name="distributorSearchForm" property="distributorId" styleClass="txfield">
                            <html:option value="0">All Distributor</html:option>
                            <html:options collection="distributorList" property="value" labelProperty="label"/>
                        </html:select>
                    </td>
                    <TD width="5%">&nbsp;</TD>
                    <TD width="10%" class=NArialL>&nbsp;</TD>
                    <TD width="10%" class=NArialL>&nbsp;</td>
				</tr>
				<tr><td colspan="6"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
                <tr>
                    <td width="15%">&nbsp;</td>
                    <TD width="15%" class=NArialL>From-Date :</TD>
                    <TD width="15%" class=NArialL>
                        <html:text property="fromDate" name="distributorSearchForm" styleClass="txfield" size="12"/>&nbsp;
                            <a href="javascript:openCalendar(document.distributorSearchForm.datefrom)">
                            <img onMouseOver="window.status='Click here to select From date';return true" onMouseOut="window.status='';return true" border="0" align='center' title="Click here to Select From Date"
                            src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20></a>
                    </TD>

                    <TD width="10%" class=NArialL>To-Date :</TD>
                    <TD width="10%" class=NArialL>
                        <html:text property="toDate" name="distributorSearchForm" styleClass="txfield" size="12"/>&nbsp;
                            <a href="javascript:openCalendar(document.distributorSearchForm.dateto)">
                            <img onMouseOver="window.status='Click here to select To date';return true" onMouseOut="window.status='';return true" border="0" align='center' title="Click here to Select To Date"
                            src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20></a>
                    </TD>
                    <TD width="5%">&nbsp;</TD>
            </tr>
            <tr><td colspan="6"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
            <TR>
                <TD colspan="1">&nbsp;</TD>
                <TD width="15%" class=NArialL >
                   <html:radio name="distributorSearchForm" property="reportType" value="salesReport">Sales</html:radio>
                </TD>
                <TD width="15%" class=NArialL >
                    <html:radio name="distributorSearchForm" property="reportType" value="inventoryReport">Inventory </html:radio>
                </TD>
                <TD colspan="3">&nbsp;</TD>
            </TR>
            <tr><td colspan="6"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
            <tr>
                <td colspan="4">&nbsp;</td>
                <td colspan= "1" align="left" valign="top">
                <a class="NArialL" href="javascript:submitPage(2)"  onMouseOver="window.status='Click here to Export to Excel';return true" onMouseOut="window.status='';return true" title='Click here to Export to Excel' >Export to Excel</a>
                </td>
                <td colspan= "1">&nbsp;</td>
            </tr>
            <tr><td colspan="6"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
            <tr>
                <td colspan="6" align="center">
                    <a href="javascript:submitPage(1);">
                    <img border="0" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" width="53" height="17" onMouseOver="window.status='Click to Generate Report';return true" onmouseout="window.status='';return true" title="Click here to Generate Report"/></a>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="javascript:document.distributorSearchForm.reset();"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17" onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"></a>
                </td>
            </tr>
          </table>
        </html:form>
<!-- body ends here -->
		</td>
	</tr>
	</tbody>
</TABLE>

<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>

<!-- footer end here -->

</BODY>
</HTML>
<%--<% }catch(Exception e){e.printStackTrace();} %>--%>

